<?php
include './check_elapsed_event.php';
sec_session_start ();

if (isset ( $_COOKIE ['login_string'] )) {
	$login_string = $_COOKIE ['login_string'];
	$username = $_COOKIE ['username'];
	$user_id = $_COOKIE ['user_id'];
	
	$_SESSION ['user_id'] = $user_id;
	$_SESSION ['login_string'] = $login_string;
	$_SESSION ['username'] = $username;
}
if (login_check ( $mysqli ) == true) {
	$username = $_SESSION ['username'];
	global $ruolo;
	$query_ruolo = "SELECT ruolo, saldo FROM members WHERE username='" . $username . "' LIMIT 1";
	if ($result = $mysqli->query ( $query_ruolo )) {
		while ( $row = $result->fetch_assoc () ) {
			$ruolo = $row ['ruolo'];
		}
		$result->free ();
	}
	
	$query_fornitori = "SELECT vendors.appellative,vendors.id_vendor FROM vendors WHERE vendors.id_vendor NOT IN(SELECT vendor FROM orders WHERE active='1')";
	if ($result = $mysqli->query ( $query_fornitori )) {
		while ( $row = $result->fetch_assoc () ) {
			$id [] = $row ['id_vendor'];
			$appellative [] = $row ['appellative'];
		}
		$result->free ();
	}
	
	?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Crea Ordine</title>

<!-- Bootstrap -->
<link href="../css/bootstrap.min.css" rel="stylesheet">
<link href="../css/neworder.css" rel="stylesheet">
<link href="../css/jquery.simple-dtpicker.css" rel="stylesheet">
<!-- jQuery (necessario per i plugin Javascript di Bootstrap) -->
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> -->
<script src="../js/jquery_1_11_2.js"></script>
<script src="../js/jquery.simple-dtpicker.js"></script>
<!-- Includi tutti i plugin compilati (sotto), o includi solo i file individuali necessari -->
<script src="../js/bootstrap.min.js"></script>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js non funziona se guardate la pagina attraverso file:// -->
<!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
<script>
$(function() {
	$('#datafinale').appendDtpicker({
		"autodateOnStart": false,
	});
});
$('#salva').on('click', check_select);
var check_select=function(e){
	if ($('[name=venditore]').val()=='--'){ 
		$(this).focus();
		
		return false; }
	alert('sono qua');
	return true;
}

</script>
</head>
<body>
	<!-- 	barra di navigazione -->
	<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
		<div class="container">
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed"
					data-toggle="collapse" data-target="#menu_links">
					<span class="sr-only">Toggle navigation</span> <span
						class="icon-bar"></span> <span class="icon-bar"></span> <span
						class="icon-bar"></span>
				</button>
				<a href="./home.php"><img src="../images/logo.png" height=45px
					width=45px></a>
			</div>
			<div class="collapse navbar-collapse" id=menu_links>
				<ul class="nav navbar-nav">
					<li><a href="./home.php"><span class="glyphicon glyphicon-home"
							aria-hidden="true"></span>&nbsp;Home</a></li>
					<li><a href="profile.php">Profile</a></li>
					<li><a href="messages">Messages</a></li>
				</ul>
				<p class="navbar-text navbar-right">
					Signed in as <a href="#" class="navbar-link"><mark><?php echo $username?></mark></a>&nbsp;&nbsp;&nbsp;<a
						href="../login/logout.php" class="navbar-link"><span
						class="glyphicon glyphicon-log-out" aria-hidden="true"></span>Logout</a>
				</p>
			</div>
		</div>
	</nav>

	<!-- contenitore della pagina -->
	<div class=container>
		<div class=container id=form_container>
			<form class="form-signin" id=new_order method=POST
				action='neworder_process.php'>
				<h2 class="form-signin-heading">Nuovo ordine</h2>
				<div class="form-group">
					<label for="fornitore">Fornitore</label> <select name=venditore>
						<option value='--' selected>seleziona</option>
					<?php
	for($i = 0; $i < count ( $appellative ); $i ++) {
		echo "<option value=" . $id [$i] . ">" . $appellative [$i] . "</option>";
	}
	
	?>
				</select>
				</div>
				<div class="form-group">
					<label for="Chiusura">Data ed ora di chiusura ordine</label> <input
						type='text' name=datafinale id=datafinale required>
				</div>


				<div class="form-group">
					<label for="commento">Commento</label>
					<textarea name=commento class="form-control" rows="3"
						maxlength="255">
				</textarea>
				</div>
				<button id=salva type="submit" class='btn btn-default btn-lg btn-block'>Start</button>
			</form>
		</div>
	</div>

</body>
</html>

<?php
} else {
	header ( "Location: ../login/login.php" );
	// echo 'You are not authorized to access this page, please login. <br/>';
}
?>
